package ar.com.solidussource.howmuchmobile.activities;

import android.content.Intent;
import android.widget.*;
import ar.com.solidussource.howmuchmobile.activities.filter.CurrentFilter;
import ar.com.solidussource.howmuchmobile.activities.generic.PaginatedGenListActivity;
import ar.com.solidussource.howmuchmobile.common.entities.Location;
import ar.com.solidussource.howmuchmobile.common.exception.ServiceException;
import ar.com.solidussource.howmuchmobile.services.LocationRestService;

/**
 * Created with IntelliJ IDEA.
 * User: FT31270775
 * Date: 07/11/12
 * Time: 12:06
 * To change this template use File | Settings | File Templates.
 */
public class LocationListActivity extends PaginatedGenListActivity<Location> {

    @Override
    public String getViewTitle() {
        return "Localidades";  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void serviceCall() throws ServiceException {
        Integer provinceId = getIntent().getExtras().getInt("provinceId");

        LocationRestService locationRestService = new LocationRestService();
        data.addAll(locationRestService.getLocations(provinceId, pageNumber, size));
    }

    @Override
    public Integer getElementId(int position) {
        return data.get(position).getId();
    }

    @Override
    public String getElementName(int position) {
        return data.get(position).getName();
    }

    @Override
    public void onElementClick(int position) {
        CurrentFilter.setLocation(data.get(position));

        Toast toast1 = Toast.makeText(getApplicationContext(), "Localidad Seleccionada!", Toast.LENGTH_SHORT);
        toast1.show();

        Intent intent = new Intent(LocationListActivity.this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        startActivity(intent);
    }
}